package sectorCrack.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;

import sectorCrack.bean.Dat;
import sectorCrack.manager.DataToByteConverter;

public class ByteFileCreator {

	public static byte[] intToByte(int i) {
		ByteBuffer br = ByteBuffer.allocate(4);
		br.order(ByteOrder.LITTLE_ENDIAN);
		br.putInt(i);
		return br.array();
	}

	public static void createFile(byte[] bytes, String filename) throws IOException {
		File outFile = new File(filename);
		FileOutputStream out = new FileOutputStream(outFile);
		out.write(bytes);
		out.close();
	}

	public static void createFile(ArrayList<Dat> data, String filename) throws IOException {
		File outFile = new File(filename);
		FileOutputStream out = new FileOutputStream(outFile);
		for (Dat dat : data) {
			byte[] bs = DataToByteConverter.datToByteArray(dat);
			out.write(bs);
		}

		out.close();
	}

}
